package com.haixiaoke.saas.enterprise.lock.controller;

import java.util.List;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.lock.domain.LockPwd;
import com.haixiaoke.saas.lock.service.ILockPwdService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 锁密码授权Controller
 * 
 * @author panda
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/enterprise/lock/pwd")
public class EnterpriseLockPwdController extends BaseController {
    @Autowired
    private ILockPwdService lockPwdService;

    /**
     * 查询锁密码授权列表
     */
    @GetMapping("/page")
    public TableDataInfo list(LockPwd lockPwd) {
        startPage();
        List<LockPwd> list = lockPwdService.selectLockPwdList(lockPwd);
        return getDataTable(list);
    }

    /**
     * 新增锁密码授权
     */
    @Log(title = "锁密码授权", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LockPwd lockPwd) {
        lockPwd.setUserName("平台");
        return lockPwdService.insertLockPwd(lockPwd);
    }

    /**
     * 密码授权禁用/启用
     */
    @PutMapping("/editPwdState/{pwdId}")
    public AjaxResult editPwdState(@PathVariable("pwdId") Long pwdId) {
        return lockPwdService.editPwdState(pwdId);
    }

    /**
     * 删除锁密码授权
     */
    @Log(title = "锁密码授权", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pwdId}")
    public AjaxResult remove(@PathVariable Long pwdId) {
        return lockPwdService.deleteLockPwdByPwdId(pwdId);
    }
}
